#coding=utf8
import pymysql

def connect_mysql():
    try:
        db = pymysql.connect(host='118.24.188.90',port=3306,user='root',passwd='si1OCDvrr4WitsVi',db='spider',charset='utf8')
        return db
    except Exception as e:
        return false

def exe_db(db,sql):
    try:
        cursor = db.cursor()
        db.ping(reconnect=True)
        cursor.execute(sql)
        db.commit()
    except Exception as e:
        return false

def select_db(db,sql):
    try:
        cursor = db.cursor()
        db.ping(reconnect=True)
        cursor.execute(sql)
        return cursor.fetchall()
    except Exception as e:
        return false